//
//  AnswerTableViewCell.m
//  PTravel
//
//  Created by dllo on 15/12/3.
//  Copyright © 2015年 李涵. All rights reserved.
//

#import "AnswerTableViewCell.h"

@implementation AnswerTableViewCell
- (void)dealloc
{
    [_title release];
    [_userName release];
    [_answer release];
    [_content release];
    [_answerN release];
    [_request release];
    [_requestN release];
    [_prettyDate release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
       
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changColor) name:@"night" object:nil];
            [self createSubViews];
    }
    return self;
}
- (void)changColor
{
    self.backgroundColor = CELLCOLOR;
}

- (void)createSubViews
{
    self.title = [[UILabel alloc] initWithFrame:CGRectMake(15, 8, BOUNDS.size.width-30, 40)];
    self.title.font = [UIFont systemFontOfSize:14];
   
    self.title.numberOfLines = 2;
   
    [self.contentView addSubview:self.title];
    [_title release];
    
    self.content = [[UILabel alloc] initWithFrame:CGRectMake(self.title.frame.origin.x, 50, BOUNDS.size.width-30, 40)];
    self.content.font = [UIFont systemFontOfSize:13];
    self.content.numberOfLines = 2;
    [self.contentView addSubview:self.content];
    [_content release];
    
    self.userName = [[UILabel alloc] initWithFrame:CGRectMake(15, 90, 1, 15)];
    self.userName.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.userName];
    [_userName release];
    
    self.prettyDate = [[UILabel alloc] initWithFrame:CGRectMake(self.userName.frame.origin.x+self.userName.frame.size.width+10, self.userName.frame.origin.y, 100, 15)];
    self.prettyDate.font = [UIFont systemFontOfSize:12];
    self.prettyDate.textColor = [UIColor colorWithRed:1.000 green:0.221 blue:0.847 alpha:1.000];
    [self.contentView addSubview:self.prettyDate];
    [_prettyDate release];
    
    self.request = [[UILabel alloc] initWithFrame:CGRectMake(BOUNDS.size.width-120, self.userName.frame.origin.y+5, 30, 15)];
    self.request.text = @"问问";
    self.request.font = [UIFont systemFontOfSize:12];
    self.request.textColor = TEXTCOLOR;
    [self.contentView addSubview:self.request];
    [_request release];
    
    self.requestN = [[UILabel alloc] initWithFrame:CGRectMake(self.request.frame.origin.x+30, self.request.frame.origin.y, 40, 15)];
    self.requestN.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.requestN];
    [_requestN release];
    
    self.answer = [[UILabel alloc] initWithFrame:CGRectMake(self.requestN.frame.origin.x+40, self.requestN.frame.origin.y, 30, 15)];
    self.answer.text = @"回答";
    self.answer.font = [UIFont systemFontOfSize:12];
    self.answer.textColor = TEXTCOLOR;
    [self.contentView addSubview:self.answer];
    [_answer release];
    
    self.answerN = [[UILabel alloc] initWithFrame:CGRectMake(self.answer.frame.origin.x+30, self.answer.frame.origin.y, 40, 15)];
    self.answerN.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.answerN];
    [_answerN release];
}

- (void)setAanswer:(Answer *)aanswer
{
    if (_aanswer != aanswer) {
        [_aanswer release];
        _aanswer = [aanswer retain];
    }
    
    self.title.text = aanswer.title;
    self.content.text = aanswer.content;
    self.userName.text = aanswer.author;
    CGSize size =[aanswer.author sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}];
    CGRect tempFrame2 = self.userName.frame;
    tempFrame2.size.width = size.width;
    self.userName.frame = tempFrame2;
    
    
    
    self.requestN.text = [NSString stringWithFormat:@"%d", aanswer.ask_num.intValue];
    self.answerN.text = [NSString stringWithFormat:@"%d",aanswer.answer_num.intValue];
    self.prettyDate.frame = CGRectMake(self.userName.frame.origin.x+self.userName.frame.size.width+10, self.userName.frame.origin.y, 100, 15);
    self.prettyDate.text = [AppTools prettyDateWithReference:[NSDate dateWithTimeIntervalSince1970:aanswer.add_time.intValue]];
    self.content.textColor = TEXTCOLOR;
    self.title.textColor = TEXTCOLOR;
    self.userName.textColor = TEXTCOLOR;
    self.requestN.textColor = TEXTCOLOR;
    self.answerN.textColor = TEXTCOLOR;

}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
